package me.leiusual.sharing.ui.useraccount.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.UserAccountLog

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountDetailAdapter(
    private val type: String
) : PagedListAdapter<UserAccountLog, UserAccountDetailViewHolder>(DIFF_CALLBACK) {

  companion object {
    private val DIFF_CALLBACK = object : DiffUtil.ItemCallback<UserAccountLog>() {
      override fun areItemsTheSame(oldItem: UserAccountLog, newItem: UserAccountLog): Boolean {
        return oldItem.id == newItem.id
      }

      override fun areContentsTheSame(oldItem: UserAccountLog, newItem: UserAccountLog): Boolean {
        return oldItem == newItem
      }
    }
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserAccountDetailViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_user_account_detail, parent, false)
    return UserAccountDetailViewHolder(type, itemView)
  }

  override fun onBindViewHolder(holder: UserAccountDetailViewHolder, position: Int) {
    holder.bind(getItem(position) ?: return)
  }
}